//noinspection JSUnresolvedFunction
var SSSAPP = angular.module('ShiShiSalesAPP', ['ui.bootstrap', 'ngAnimate', 'ui.router', 'utils', 'ngTouch', 'ui-lazyload'])
    .config(function ($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider) {
        $locationProvider.html5Mode(true);
        $stateProvider
            .state('home', {
                url: '/Home/Router/home',
                templateUrl: '/Home/Index/home',
                controller: 'HomeCtrl'
            })
            .state('cart', {
                url: '/Home/Router/cart',
                templateUrl: '/Home/Index/cart',
                controller: 'CartCtrl'
            })
            .state('gpon', {
                url: '/Home/Router/gpon?setid&page&gponid',
                templateUrl: '/Home/Index/gpon',
                controller: 'GponCtrl'
            })
            .state('detail', {
                url: '/Home/Router/detail?cid&former',
                templateUrl: '/Home/Index/detail',
                controller: 'DetailCtrl'
            })
            .state('center', {
                url: '/Home/Router/center',
                templateUrl: '/Home/Index/center',
                controller: 'CenterCtrl'
            })
            .state('center_setting', {
                url: '/Home/Router/center_setting',
                templateUrl: '/Home/Index/center_setting'
            })
            .state('center_setting_pwdmodify', {
                url: '/Home/Router/center_setting_pwdmodify',
                templateUrl: '/Home/Index/center_setting_pwdmodify',
                controller: 'CenterSettingPwdModifyCtrl'
            })
            .state('ordercenter', {
                url: '/Home/Router/ordercenter?pageno&state',
                templateUrl: '/Home/Index/ordercenter',
                controller: 'OrderCenterCtrl'
            })
            .state('orderdetail', {
                url: '/Home/Router/orderdetail?orderid',
                templateUrl: '/Home/Index/orderdetail',
                controller: 'OrderDetail'
            })
            .state('order', {
                url: '/Home/Router/order?biztype&gponid&setid',
                templateUrl: '/Home/Index/order',
                controller: 'OrderCtrl'
            })
            .state('express', {
                url: '/Home/Router/express?former&biztype&setid&gponid',
                templateUrl: '/Home/Index/express',
                controller: 'ExpressCtrl'
            })
            .state('expressOp', {
                url: '/Home/Router/expressOp?operate&uid&former',
                templateUrl: '/Home/Index/expressOp',
                controller: 'ExpressOperateCtrl'
            })
            .state('pay', {
                url: '/Home/Router/pay?orderid',
                templateUrl: '/Home/Index/pay',
                controller: 'PayCtrl'
            })
            .state('tuixian', {
                url: '/Home/Router/tuixian?bm_id',
                templateUrl: '/Home/Index/tuixian',
                controller: 'TuiXianCtrl'
            })
            .state('category', {
                url: '/Home/Router/category?cate_id',
                templateUrl: '/Home/Index/category',
                controller: 'CategoryCtrl'
            });
        $urlRouterProvider.otherwise('/Home/Router/home');
        $httpProvider.interceptors.push('globalloading');

    })
    .factory('globalloading', ['$rootScope', '$timeout', function ($rootScope, $timeout) {
        var globalloadingAjax = [
            '/Home/BlockManage/ajaxGetIndexInfo',
            '/Home/Cart/ajaxGetCartList',
            '/Home/Groupon/ajaxMyGponList',
            '/Home/Groupon/ajaxHotGponList',
            '/Home/Groupon/ajaxGetGponInfo',
            '/Home/Commodity/ajaxGetCommodityInfo',
            '/Home/Order/ajaxGetOrderList',
            '/Home/Order/ajaxGetCartOrder',
            '/Home/Order/ajaxGetUserAddress',
            '/Home/Order/ajaxGetOrderInfo',
            '/Home/BlockManage/ajaxGetIndexCommodityByCateId'
        ];
        return {
            request: function (config) {
                if (inArray(config.idx, globalloadingAjax)) {
                    $rootScope.globalloading = true;
                }
                return config;
            },
            response: function (response) {
                if ($rootScope.globalloading == true) {
                    $timeout(function () {
                        $rootScope.globalloading = false;
                    }, 600);
                }
                return response;
            }
        };
    }]);
